﻿using System.Drawing;

using Microsoft.AspNetCore.Mvc;

namespace PageOffice6_Net_Core.Controllers.MergeExcelCell
{
    public class MergeExcelCellController : Controller
    {
        public IActionResult Excel()
        {
            PageOfficeNetCore.PageOfficeCtrl poCtrl = new PageOfficeNetCore.PageOfficeCtrl(Request);

            PageOfficeNetCore.Excel.WorkbookWriter wb = new PageOfficeNetCore.Excel.WorkbookWriter();
            PageOfficeNetCore.Excel.SheetWriter sheet = wb.OpenSheet("Sheet1");
            //合并单元格
            sheet.OpenTable("B2:F2").Merge();
            PageOfficeNetCore.Excel.ExcelCellWriter cB2 = sheet.OpenCell("B2");
            cB2.Value = "北京某公司产品销售情况";
            //设置水平对齐方式
            cB2.HorizontalAlignment = PageOfficeNetCore.Excel.XlHAlign.xlHAlignCenter;
            cB2.ForeColor = Color.Red;
            cB2.Font.Size = 16;

            sheet.OpenTable("B4:B6").Merge();//合并单元格
            PageOfficeNetCore.Excel.ExcelCellWriter cB4 = sheet.OpenCell("B4");
            cB4.Value = "A产品";
            //设置水平对齐方式
            cB4.HorizontalAlignment = PageOfficeNetCore.Excel.XlHAlign.xlHAlignCenter;
            //设置垂直对齐方式
            cB4.VerticalAlignment = PageOfficeNetCore.Excel.XlVAlign.xlVAlignCenter;

            sheet.OpenTable("B7:B9").Merge();//合并单元格
            PageOfficeNetCore.Excel.ExcelCellWriter cB7 = sheet.OpenCell("B7");
            cB7.Value = "B产品";
            cB7.HorizontalAlignment = PageOfficeNetCore.Excel.XlHAlign.xlHAlignCenter;
            cB7.VerticalAlignment = PageOfficeNetCore.Excel.XlVAlign.xlVAlignCenter;

            poCtrl.SetWriter(wb);

            //打开Excel文档
            poCtrl.WebOpen("doc/test.xls", PageOfficeNetCore.OpenModeType.xlsNormalEdit, "tom");
            ViewBag.poCtrl = poCtrl.GetHtml();
            return View();
        }

    }
}